package net.huashitong.supervision.task.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.supervision.task.dao.TaskCategoryDao;
import net.huashitong.supervision.task.entity.TaskBackNew;
import net.huashitong.supervision.task.entity.TaskCategory;
import net.huashitong.supervision.task.filter.TaskCategoryFilter;
import net.huashitong.supervision.task.util.HolidayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/8/6
 * Time: 20:27
 * To change this template use File | Settings | File Templates.
 * Description:s
 */
@Service
public class TaskCategoryService extends StringPKService<TaskCategory> {
    @Autowired
    private SysTableService tableService;
    @Autowired
    private TaskCategoryDao taskCategoryDao;
    @Override
    protected BaseDao<TaskCategory, String> getDao() {
        return taskCategoryDao;
    }
    public void save(TaskCategory taskCategory, String userId){
        Date date = new Date();
        String date1 = HolidayUtils.sdf1.format(date);
        String time = HolidayUtils.sdf2.format(date);
        taskCategory.setSysId(tableService.updateMaxSysId("t_task_category",null));
        taskCategory.setCreateUser(userId);
        taskCategory.setUpdUser(userId);
        taskCategory.setCreateDate(date1);
        taskCategory.setCreateTime(time);
        taskCategory.setUpdDate(date1);
        taskCategory.setUpdTime(time);
        getDao().save(taskCategory);
    }
    @Override
    protected void beforeSave(TaskCategory obj) {
        obj.setSysId(tableService.updateMaxSysId("t_task_category", null));
    }

    public List<TaskCategory> queryFilter(TaskCategoryFilter filter) {
        return taskCategoryDao.queryFilter(filter);
    }

    public int queryMaxIndex() {
        return taskCategoryDao.queryMaxIndex();
    }
}
